package com.example.tests;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import org.testng.annotations.Test;
import com.example.fw.HibernateHelper;
import com.example.utils.SortedListOf;

public class PrintPhonesTests extends TestBase {

	@Test
	  public void PrintPhonesValidation() throws Exception {
	    
	    HibernateHelper contactHelper = app.getHibernateHelper();
		SortedListOf<ContactData> contactList = new SortedListOf<ContactData>(contactHelper.listContacts());
		    
		SortedListOf<ContactDataPhone> printPhonesList = app.getContactHelper().getPhonesData();
		app.getContactHelper().returnFromPrintPage();
	    
	    System.out.println(contactList);
	    System.out.println(printPhonesList);
	    
	    assertThat(printPhonesList.size(), equalTo(contactList.size()));
	    ContactDataPhone.assertPrintContactsEqual(printPhonesList, contactList); 
	    
	    if (wantToCheck()) {
	    	if ("yes".equals(app.getProperty("check.ui"))) {
				  
				  SortedListOf<ContactDataRow> mdContacts = ContactDataRow.buildFromContactList(app.getModel().getContacts()); 	  
				  SortedListOf<ContactDataRow> uiContacts = app.getContactHelper().getUIContacts();
				  
				  assertThat("UI verification failed", mdContacts, equalTo(uiContacts));
				  System.err.println("UI verification passed");
			}
		}

	  }
	   
}
